package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkGeneratePaper

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkCustomTemplet.CustomTemplet
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TempletExceedList
import kotlinx.android.synthetic.main.aibk_adapter_item_difficulty_rank.view.*

class AibkGenerateDifficultySettingAdapter(
        val activity: AppCompatActivity,
        val templetExceedList: TempletExceedList
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_difficulty_rank, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        holder.convertView.BtnDifficultySetting.text = templetExceedList[position].Name
        holder.convertView.BtnDifficultySetting.isSelected = templetExceedList[position].IsChecked

        holder.convertView.BtnDifficultySetting.setOnClickListener {
            holder.convertView.BtnDifficultySetting.isSelected = !holder.convertView.BtnDifficultySetting.isSelected
            for(i in 0 until templetExceedList.size){
                templetExceedList[i].IsChecked = i == position
                if(i == position){
                    val level = templetExceedList[i].Level
                    onClickListener!!.onCheckLevel(level)
                }
            }
            notifyDataSetChanged()
        }
    }

    override fun getItemCount(): Int {
        return templetExceedList.size
    }

    interface OnClickListener {
        fun onCheckLevel(level:Int)//选择生词率难度等级
    }

    private var onClickListener: OnClickListener? = null

    fun setOnClickListener(mOnClickListener: OnClickListener?) {
        onClickListener = mOnClickListener
    }

}